home *** CD-ROM | disk | FTP | other *** search
-
- <HTML>
- <HEAD><TITLE>
- ChooseFont Demo</TITLE>
- </HEAD>
- <BODY bgColor=#ffffff text=#000000>
- <H1><font color==ff0000>Font Dialog Box</font></H1>
-
- <P>The <B>Font </B>dialog box lets the user choose attributes for a logical
- font, such as typeface name, style (bold, italic, or regular), point size,
- effects (underline, strikeout, and text color), and a script (or character set).
- </P>
- <P>You create and display a <B>Font</B> dialog box by initializing a <B>CHOOSEFONT</B>
- structure and passing the structure to the <B>ChooseFont</B>
- function. </P>
- <P>The following illustration shows a typical <B>Font</B> dialog box.</P>
- <P><IMG alt="" border=0 src="cfdemo.bmp"></P>
- <P>If the user clicks the <B>OK</B> button, <B>ChooseFont</B> returns TRUE and
- sets the members of the <B>LOGFONT</B>
- structure pointed to by the <B>lpLogFont</B> member of the <B>CHOOSEFONT</B>
- structure. You can use the <B>LOGFONT</B> structure with the <B>CreateFontIndirect</B>
- function to create a logical font. <B>ChooseFont</B> also sets other
- <B>CHOOSEFONT</B> members to indicate the user's selections.</P>
- <P>If the user cancels the <B>Font</B> dialog box or an error occurs, <B>ChooseFont</B>
- returns FALSE and the contents of the <B>LOGFONT</B> structure are not defined.
- You can determine the cause of an error by using the <B>CommDlgExtendedError</B>
- function to retrieve the extended error value. </P></font>
-
- <H1><font color=#ff0000>CHOOSEFONT</font></H1>
-
- <P>The <B>CHOOSEFONT</B> structure contains information that the <B>ChooseFont</B>
- function uses to initialize the <B>Font</B> common dialog box. After the user
- closes the dialog box, the system returns information about the user's selection
- in this structure. </P>
- <PRE><CODE>typedef struct { // cf
- DWORD lStructSize;
- HWND hwndOwner;
- HDC hDC;
- LPLOGFONT lpLogFont;
- INT iPointSize;
- DWORD Flags;
- DWORD rgbColors;
- LPARAM lCustData;
- LPCFHOOKPROC lpfnHook;
- LPCTSTR lpTemplateName;
- HINSTANCE hInstance;
- LPTSTR lpszStyle;
- WORD nFontType;
- WORD ___MISSING_ALIGNMENT__;
- INT nSizeMin;
- INT nSizeMax;
- } CHOOSEFONT;
- </CODE></PRE>
-
- <H4>Members</H4>
-
- <DL>
- <DT><B>lStructSize</B>
- <DD>Specifies the length, in bytes, of the structure.
- <DT><B>hwndOwner</B>
- <DD>Identifies the window that owns the dialog box. This member can be any
- valid window handle, or it can be NULL if the dialog box has no owner.
- <DT><B>hDC</B>
- <DD>Identifies the device context (or information context) of the printer
- whose fonts will be listed in the dialog box. This member is used only if the
- <B>Flags</B> member specifies the CF_PRINTERFONTS or CF_BOTH flag; otherwise,
- this member is ignored.
- <DT><B>lpLogFont</B>
- <DD>Pointer to a <B>LOGFONT</B></A>
- structure. If you set the CF_INITTOLOGFONTSTRUCT flag in the <B>Flags</B>
- member and initialize the <B>LOGFONT</B> members, the <B>ChooseFont</B>
- function initializes the dialog box with a font that is the closest possible
- match. If the user clicks the <B>OK</B> button, <B>ChooseFont</B> sets the
- members of the <B>LOGFONT</B> structure based on the user's selections.
- <DT><B>iPointSize</B>
- <DD>Specifies the size of the selected font, in units of 1/10 of a point. The
- <B>ChooseFont</B> function sets this value after the user closes the dialog
- box.
- <DT><B>Flags</B>
- <DD>A set of bit flags that you can use to initialize the <B>Font</B> common
- dialog box. When the dialog box returns, it sets these flags to indicate the
- user's input. This member can be a combination of the following flags:
- <TABLE cellPadding=0 cellSpacing=0 cols=2>
- <TR vAlign=top>
- <TH align=left width=49%>Flag</TH>
- <TH align=left width=51%>Meaning</TH></TR>
-
- <TR vAlign=top>
- <TD width=49%>CF_APPLY</TD>
- <TD width=51%>Causes the dialog box to display the Apply button. You
- should provide a hook procedure to process WM_COMMAND
- messages for the Apply button. The hook procedure can send the WM_CHOOSEFONT_GETLOGFONT
- message to the dialog box to retrieve the address of the <B>LOGFONT</B></A>
- structure that contains the current selections for the font. </TD></TR>
-
- <TR vAlign=top>
- <TD width=49%>CF_ANSIONLY</TD>
- <TD width=51%>This flag is obsolete. To limit font selections to all
- scripts except those that use the OEM or Symbol character sets, use
- CF_SCRIPTSONLY. To get the Windows 3.1 CF_ANSIONLY behavior, use
- CF_SELECTSCRIPT and specify ANSI_CHARSET in the <B>lfCharSet</B> member
- of the <B>LOGFONT</B> structure pointed to by <I>lpLogFont</I>.</TD></TR>
-
- <TR vAlign=top>
- <TD width=49%>CF_BOTH</TD>
- <TD width=51%>Causes the dialog box to list the available printer and
- screen fonts. The <B>hDC</B> member identifies the device context (or
- information context) associated with the printer. This flag is a
- combination of the CF_SCREENFONTS and CF_PRINTERFONTS flags.</TD></TR>
-
- <TR vAlign=top>
- <TD width=49%>CF_TTONLY</TD>
- <TD width=51%>Specifies that <B>ChooseFont</B>
- should only enumerate and allow the selection of TrueType fonts.</TD></TR>
-
- <TR vAlign=top>
- <TD width=49%>CF_EFFECTS</TD>
- <TD width=51%>Causes the dialog box to display the controls that allow
- the user to specify strikeout, underline, and text color options. If
- this flag is set, you can use the <B>rgbColors</B> member to specify the
- initial text color. You can use the <B>lfStrikeOut</B> and
- <B>lfUnderline</B> members of the <B>LOGFONT</B>
- structure pointed to by <B>lpLogFont</B> to specify the initial settings
- of the strikeout and underline check boxes. <B>ChooseFont</B> can use
- these members to return the user's selections.</TD></TR>
-
- <TR vAlign=top>
- <TD width=49%>CF_ENABLEHOOK</TD>
- <TD width=51%>Enables the hook procedure specified in the
- <B>lpfnHook</B> member of this structure.</TD></TR>
-
- <TR vAlign=top>
- <TD width=49%>CF_ENABLETEMPLATE</TD>
- <TD width=51%>Indicates that the <B>hInstance</B> and
- <B>lpTemplateName</B> members specify a dialog box template to use in
- place of the default template.</TD></TR>
-
- <TR vAlign=top>
- <TD width=49%>CF_ENABLETEMPLATEHANDLE</TD>
- <TD width=51%>Indicates that the <B>hInstance</B> member identifies a
- data block that contains a preloaded dialog box template. The system
- ignores the <B>lpTemplateName</B> member if this flag is
- specified.</TD></TR>
-
- <TR vAlign=top>
- <TD width=49%>CF_FIXEDPITCHONLY</TD>
- <TD width=51%>Specifies that <B>ChooseFont</B>
- should select only fixed-pitch fonts.</TD></TR>
-
- <TR vAlign=top>
- <TD width=49%>CF_FORCEFONTEXIST</TD>
- <TD width=51%>Specifies that <B>ChooseFont</B> should indicate an error
- condition if the user attempts to select a font or style that does not
- exist.</TD></TR>
-
- <TR vAlign=top>
- <TD width=49%>CF_INITTOLOGFONTSTRUCT</TD>
- <TD width=51%>Specifies that <B>ChooseFont</B> should use the <B>LOGFONT</B>
- structure pointed to by the <B>lpLogFont</B> member to initialize the
- dialog box controls.</TD></TR>
-
- <TR vAlign=top>
- <TD width=49%>CF_LIMITSIZE</TD>
- <TD width=51%>Specifies that <B>ChooseFont</B>
- should select only font sizes within the range specified by the
- <B>nSizeMin</B> and <B>nSizeMax</B> members.</TD></TR>
-
- <TR vAlign=top>
- <TD width=49%>CF_NOOEMFONTS</TD>
- <TD width=51%>Same as the CF_NOVECTORFONTS flag.</TD></TR>
-
- <TR vAlign=top>
- <TD width=49%>CF_NOFACESEL</TD>
- <TD width=51%>When using a <B>LOGFONT</B> structure to initialize the
- dialog box controls, use this flag to selectively prevent the dialog box
- from displaying an initial selection for the font name combo box. This
- is useful when there is no single font name that applies to the text
- selection. </TD></TR>
-
- <TR vAlign=top>
- <TD width=49%>CF_NOSCRIPTSEL</TD>
- <TD width=51%>Disables the <B>Script</B> combo box. When this flag is
- set, the <B>lfCharSet</B> member of the <B>LOGFONT</B>
- structure is set to DEFAULT_CHARSET when <B>ChooseFont</B>
- returns. This flag is used only to initialize the dialog box.</TD></TR>
-
- <TR vAlign=top>
- <TD width=49%>CF_NOSTYLESEL</TD>
- <TD width=51%>When using a <B>LOGFONT</B> structure to initialize the
- dialog box controls, use this flag to selectively prevent the dialog box
- from displaying an initial selection for the font style combo box. This
- is useful when there is no single font style that applies to the text
- selection. </TD></TR>
-
- <TR vAlign=top>
- <TD width=49%>CF_NOSIZESEL</TD>
- <TD width=51%>When using a<B>LOGFONT</B>
- structure to initialize the dialog box controls, use this flag to
- selectively prevent the dialog box from displaying an initial selection
- for the font size combo box. This is useful when there is no single font
- size that applies to the text selection. </TD></TR>
-
- <TR vAlign=top>
- <TD width=49%>CF_NOSIMULATIONS</TD>
- <TD width=51%>Specifies that <B>ChooseFont</B>
- should not allow graphics device interface (GDI) font simulations.</TD></TR>
-
- <TR vAlign=top>
- <TD width=49%>CF_NOVECTORFONTS</TD>
- <TD width=51%>Specifies that <B>ChooseFont</B> should not allow vector
- font selections.</TD></TR>
-
- <TR vAlign=top>
- <TD width=49%>CF_NOVERTFONTS</TD>
- <TD width=51%>Causes the <B>Font</B> dialog box to list only
- horizontally oriented fonts.</TD></TR>
-
- <TR vAlign=top>
- <TD width=49%>CF_PRINTERFONTS</TD>
- <TD width=51%>Causes the dialog box to list only the fonts supported by
- the printer associated with the device context (or information context)
- identified by the <B>hDC</B> member.</TD></TR>
-
- <TR vAlign=top>
- <TD width=49%>CF_SCALABLEONLY</TD>
- <TD width=51%>Specifies that <B>ChooseFont</B>
- should allow only the selection of scalable fonts. (Scalable fonts
- include vector fonts, scalable printer fonts, TrueType fonts, and fonts
- scaled by other technologies.)</TD></TR>
-
- <TR vAlign=top>
- <TD width=49%>CF_SCREENFONTS</TD>
- <TD width=51%>Causes the dialog box to list only the screen fonts
- supported by the system.</TD></TR>
-
- <TR vAlign=top>
- <TD width=49%>CF_SCRIPTSONLY</TD>
- <TD width=51%>Specifies that <B>ChooseFont</B> should allow selection of
- fonts for all non-OEM and Symbol character sets, as well as the ANSI
- character set. This supersedes the CF_ANSIONLY value.</TD></TR>
-
- <TR vAlign=top>
- <TD width=49%>CF_SELECTSCRIPT</TD>
- <TD width=51%>When specified on input, only fonts with the character set
- identified in the <B>lfCharSet</B> member of the <B>LOGFONT</B>
- structure are displayed. The user will not be allowed to change the
- character set specified in the <B>Scripts</B> combo box.</TD></TR>
-
- <TR vAlign=top>
- <TD width=49%>CF_SHOWHELP</TD>
- <TD width=51%>Causes the dialog box to display the <B>Help</B> button.
- The <B>hwndOwner</B> member must specify the window to receive the HELPMSGSTRING
- registered messages that the dialog box sends when the user clicks the
- <B>Help</B> button.</TD></TR>
-
- <TR vAlign=top>
- <TD width=49%>CF_USESTYLE</TD>
- <TD width=51%>Specifies that the <B>lpszStyle</B> member points to a
- buffer that contains style data that <B>ChooseFont</B>
- should use to initialize the <B>Font</B> <B>Style</B> combo box. When
- the user closes the dialog box, <B>ChooseFont</B> copies style data for
- the user's selection to this buffer.</TD></TR>
-
- <TR vAlign=top>
- <TD width=49%>CF_WYSIWYG</TD>
- <TD width=51%>Specifies that <B>ChooseFont</B> should allow only the
- selection of fonts available on both the printer and the display. If
- this flag is specified, the CF_BOTH and CF_SCALABLEONLY flags should
- also be specified.</TD></TR>
- </TBODY>
- </TABLE>
- <BR>
- <DT><B>rgbColors</B>
- <DD>If the CF_EFFECTS flag is set, <B>rgbColors</B> specifies the initial text
- color. When <B>ChooseFont</B>
- returns successfully, this member contains the RGB value of the text color the
- user selected.
- <DT><B>lCustData</B>
- <DD>Specifies application-defined data that the system passes to the hook
- procedure identified by the <B>lpfnHook</B> member. When the system sends the
- WM_INITDIALOG
- message to the hook procedure, the message's <I>lParam</I> parameter is a
- pointer to the <B>CHOOSEFONT</B> structure specified when the dialog was
- created. The hook procedure can use this pointer to get the <B>lCustData</B>
- value.
- <DT><B>lpfnHook</B>
- <DD>Pointer to a <B>CFHookProc</B>
- hook procedure that can process messages intended for the dialog box. This
- member is ignored unless the CF_ENABLEHOOK flag is set in the <B>Flags</B>
- member.
- <DT><B>lpTemplateName</B>
- <DD>Pointer to a null-terminated string that names the dialog box template
- resource in the module identified by the <B>hInstance</B> member. This
- template is substituted for the standard dialog box template. For numbered
- dialog box resources, <B>lpTemplateName</B> can be a value returned by the <B>MAKEINTRESOURCE</B>
- macro. This member is ignored unless the CF_ENABLETEMPLATE flag is set in the
- <B>Flags</B> member.
- <DT><B>hInstance</B>
- <DD>If the CF_ENABLETEMPLATEHANDLE flag is set in the <B>Flags</B> member,
- <B>hInstance</B> is the handle of a memory object containing a dialog box
- template. If the CF_ENABLETEMPLATE flag is set, <B>hInstance</B> identifies a
- module that contains a dialog box template named by the <B>lpTemplateName</B>
- member. If neither CF_ENABLETEMPLATEHANDLE nor CF_ENABLETEMPLATE is set, this
- member is ignored.
- <DT><B>lpszStyle</B>
- <DD>Pointer to a buffer that contains style data. If the CF_USESTYLE flag is
- specified, <B>ChooseFont</B>
- uses the data in this buffer to initialize the font style combo box. When the
- user closes the dialog box, <B>ChooseFont</B> copies the string in the font
- style combo box into this buffer.
- <DT><B>nFontType</B>
- <DD>Specifies the type of the selected font when <B>ChooseFont</B> returns.
- This member can be a combination of the following values:
- <TABLE cellPadding=0 cellSpacing=0 cols=2>
- <TR vAlign=top>
- <TD width=39%><B>Value</B></TD>
- <TH align=left width=61%>Meaning</TH></TR>
-
- <TR vAlign=top>
- <TD width=39%>BOLD_FONTTYPE</TD>
- <TD width=61%>The font weight is bold. This information is duplicated in
- the <B>lfWeight</B> member of the <B>LOGFONT</B>
- structure and is equivalent to FW_BOLD.</TD></TR>
-
- <TR vAlign=top>
- <TD width=39%>ITALIC_FONTTYPE</TD>
- <TD width=61%>The italic font attribute is set. This information is
- duplicated in the <B>lfItalic</B> member of the <B>LOGFONT</B>
- structure.</TD></TR>
-
- <TR vAlign=top>
- <TD width=39%>PRINTER_FONTTYPE</TD>
- <TD width=61%>The font is a printer font.</TD></TR>
-
- <TR vAlign=top>
- <TD width=39%>REGULAR_FONTTYPE</TD>
- <TD width=61%>The font weight is normal. This information is duplicated
- in the <B>lfWeight</B> member of the <B>LOGFONT</B> structure and is
- equivalent to FW_REGULAR.</TD></TR>
-
- <TR vAlign=top>
- <TD width=39%>SCREEN_FONTTYPE</TD>
- <TD width=61%>The font is a screen font.</TD></TR>
-
- <TR vAlign=top>
- <TD width=39%>SIMULATED_FONTTYPE</TD>
- <TD width=61%>The font is simulated by the graphics device interface
- (GDI).</TD></TR>
- </TBODY>
- </TABLE>
- <BR>
- <DT><B>nSizeMin</B>
- <DD>Specifies the minimum point size a user can select. <B>ChooseFont</B>
- recognizes this member only if the CF_LIMITSIZE flag is specified.
- <DT><B>nSizeMax</B>
- <DD>Specifies the maximum point size a user can select. <B>ChooseFont</B>
- recognizes this member only if the CF_LIMITSIZE flag is specified. </DD></DL>
- </BODY></HTML>
-